/**
  ******************************************************************************
  * @file    shell.c
  * @author  zipeng
  * @version V1.0
  * @date		 2022/9/17
  * @brief   The file of shell.c usart data parse.
	* @copyright (c) 2017-2025 JZI. All rights reserved.
  ******************************************************************************
*/
#include "shell.h"
#include "usart.h"
#include "BSP_USART.h"
#include "string.h"
//#include "rm2006_pid.h"

//extern  int16_t sp1;
void Shell_Task(char *pbuf)
{
    char *ptr;

    if(strstr(pbuf,"AT+SET") == NULL){
            /***************find printf*******************/
        if(strstr(pbuf,"AT+PRINT+DATA=?")!=NULL){
//            u1_printf("sp1 kp:%.2f ki:%.2f kd:%.2f\r\n",velpid1.Kp,velpid1.Ki,velpid1.Kd);
        }
    }
    else{
         /***************set and printf*******************/
        if(strstr(pbuf,"AT+SET_VEL1_P=")!=NULL){
//            velpid1.Kp = 0.2f;
        }
        else if(strstr(pbuf,"AT+SET_VEL1_I=")!=NULL){
//            velpid1.Ki = 2;
        }
        else if(strstr(pbuf,"AT+SET_VEL1_D=")!=NULL){
//            velpid1.Kd = 0.01f;
        }
        else if(strstr(pbuf,"AT+SET_MOTOR_SP1=")!=NULL){//AT+SET_MOTOR_SP1=+1000    //AT+SET_MOTOR_SP1=-1000
            ptr = strstr(pbuf,"AT+SET_MOTOR_SP1=");//AT+SET_MOTOR_SP1=+0000
            if(*(ptr+17)=='+'){
                int16_t d = (*(ptr+18)-48)*1000 + (*(ptr+19)-48)*100 + (*(ptr+20)-48)*10 + (*(ptr+21)-48);
                if(d < 6000){
//                    sp1 = d;
                }
            }
            else if(*(ptr+17)=='-'){
                int16_t d = -1*((*(ptr+18)-48)*1000 + (*(ptr+19)-48)*100 + (*(ptr+20)-48)*10 + (*(ptr+21)-48));
                if(d > -6000){
//                    sp1 = d;
                }
            }
//            u1_printf("sp1 set ok:%d\r\n",sp1);
        }
    }
}
